<?php

namespace App\Http\Controllers\Api\Client;

use App\Http\Controllers\Controller;
use App\Models\Api\seekHouse;
use App\Services\Upload;
use Illuminate\Http\Request;
use App\Models\City;
use App\Models\Houseattr;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
class wantedHouseController extends Controller
{
//发布求租信息控制器
    protected $param;
    protected $esClient;
    protected $userId;

    //
    public function __construct(Request $request)
    {
        $this->param = $request;
//        $this->esClient = new Es();
        $this->userId = $request->get('user_id');
    }


    /**
     * 获取区域
     */
    public function getHouseData()
    {
        //区域
        $houseArea = City::getAllArea();
        //获取房产类型
        $propertyType = Houseattr::skxgetHouseattrData('house_property_type');
        $houseAttr = [
            'house_area' => $houseArea,
            'property_type'=>$propertyType
        ];
        return $this->returnJson(200, 'success', $houseAttr);
    }

    /**
     * 发布求租信息
     */
    public function releaseSaleHouse()
    {
        //接收数据
//        $paramdata = $this->param->post();
        $param = $this->param->post('wanted');
        $param['user_id'] = $this->param->post('user_id');
        $param['seek_type'] = $this->param->post('seek_type');

        //验证
        $validate = Validator::make($param, [
            'title' => 'required',
            'user_id' => 'required|numeric',
        ]);
        //判断验证结果
        if ($validate->fails()) {
            $error = $validate->errors();
            return $this->returnJson(4003, $error->first(), '');
        }

        //发布信息入库
        $addSaleHouseRes = seekHouse::create($param);
        //dd($addSaleHouseRes);
        if(!$addSaleHouseRes){
            return  "发布失败";
        }
        //支付
    }

}
